home *** CD-ROM | disk | FTP | other *** search
-
- /*********************************************************************/
- /* SAMPLE APPLICATION SKELETON */
- /* started 5/28/85 R.Z. Copyright ATARI Corp. 1985 */
- /* */
- /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
- /* */
- /* Used to build demonstrator for new FSEL function */
- /* Modified by D. N. Korte (bix dnkorte) 26 Dec 86 */
- /* */
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
- /*********************************************************************/
-
- /*********************************************************************/
- /* INCLUDE FILES */
- /*********************************************************************/
-
- #include <obdefs.h>
- #include <gemdefs.h>
- #include <osbind.h>
-
- /*********************************************************************/
- /* DEFINES */
- /*********************************************************************/
-
- #define TRUE 1
- #define FALSE 0
- #define WI_KIND (SIZER|MOVER|FULLER|CLOSER|NAME)
-
- #define NO_WINDOW (-1)
-
- #define MIN_WIDTH (2*gl_wbox)
- #define MIN_HEIGHT (3*gl_hbox)
-
- /*********************************************************************/
- /* EXTERNALS */
- /*********************************************************************/
-
- extern int gl_apid;
-
- /*********************************************************************/
- /* GLOBAL VARIABLES */
- /*********************************************************************/
-
- int gl_hchar;
- int gl_wchar;
- int gl_wbox;
- int gl_hbox; /* system sizes */
-
- int phys_handle; /* physical workstation handle */
- int handle; /* virtual workstation handle */
- int wi_handle; /* window handle */
- int top_window; /* handle of topped window */
-
- int xdesk,ydesk,hdesk,wdesk;
- int xold,yold,hold,wold;
- int xwork,ywork,hwork,wwork; /* desktop and work areas */
-
- int msgbuff[8]; /* event message buffer */
- int keycode; /* keycode returned by event-keyboard */
- int mx,my; /* mouse x and y pos. */
- int butdown; /* button state tested for, UP/DOWN */
- int ret; /* dummy return variable */
-
- int hidden; /* current state of cursor */
-
- int fulled; /* current state of window */
-
- int contrl[12];
- int intin[128];
- int ptsin[128];
- int intout[128];
- int ptsout[128]; /* storage wasted for idiotic bindings */
-
- int work_in[11]; /* Input to GSX parameter array */
- int work_out[57]; /* Output from GSX parameter array */
- int pxyarray[10]; /* input point array */
-
- /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
- /* Global variables relevant to FSEL demonstration */
- int sextn, /* bitmap for extension selection */
- driv, /* drive selector */
- stat; /* fsel return status */
- char extn3[4],extn4[4], /* "editable" extension text */
- path[256], /* directory path, sans drive, with \...\ */
- fullname[256]; /* full name with drive, path, name.extn */
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- /****************************************************************/
- /* GSX UTILITY ROUTINES. */
- /****************************************************************/
-
- hide_mouse()
- {
- if(! hidden){
- graf_mouse(M_OFF,0x0L);
- hidden=TRUE;
- }
- }
-
- show_mouse()
- {
- if(hidden){
- graf_mouse(M_ON,0x0L);
- hidden=FALSE;
- }
- }
-
- /****************************************************************/
- /* open virtual workstation */
- /****************************************************************/
- open_vwork()
- {
- int i;
- for(i=0;i<10;work_in[i++]=1);
- work_in[10]=2;
- handle=phys_handle;
- v_opnvwk(work_in,&handle,work_out);
- }
-
- /****************************************************************/
- /* set clipping rectangle */
- /****************************************************************/
- set_clip(x,y,w,h)
- int x,y,w,h;
- {
- int clip[4];
- clip[0]=x;
- clip[1]=y;
- clip[2]=x+w;
- clip[3]=y+h;
- vs_clip(handle,1,clip);
- }
-
- /****************************************************************/
- /* open window */
- /****************************************************************/
- open_window()
- {
- wi_handle=wind_create(WI_KIND,xdesk,ydesk,wdesk,hdesk);
- wind_set(wi_handle, WF_NAME," FSEL Demo ",0,0);
- graf_growbox(xdesk+wdesk/2,ydesk+hdesk/2,gl_wbox,gl_hbox,xdesk,ydesk,wdesk,hdesk);
- wind_open(wi_handle,xdesk,ydesk,310,100);
- wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
- }
-
- /****************************************************************/
- /* find and redraw all clipping rectangles */
- /****************************************************************/
- do_redraw(xc,yc,wc,hc)
- int xc,yc,wc,hc;
- {
- GRECT t1,t2;
-
- hide_mouse();
- wind_update(TRUE);
- t2.g_x=xc;
- t2.g_y=yc;
- t2.g_w=wc;
- t2.g_h=hc;
- wind_get(wi_handle,WF_FIRSTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
- while (t1.g_w && t1.g_h) {
- if (rc_intersect(&t2,&t1)) { /* anybody know where rc_intersect is documented? */
- set_clip(t1.g_x,t1.g_y,t1.g_w,t1.g_h); /* not in Abacus or Megamax docs as far as I can see... */
- write_info();
- }
- wind_get(wi_handle,WF_NEXTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
- }
- wind_update(FALSE);
- show_mouse();
- }
-
- /****************************************************************/
- /* Accessory Init. Until First Event_Multi */
- /****************************************************************/
- main()
- {
- appl_init();
- phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
- wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
- open_vwork();
- open_window();
- graf_mouse(ARROW,0x0L);
-
- hidden=FALSE;
- fulled=FALSE;
- butdown=TRUE;
-
- /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
- sextn = 0x03; /* select extn0 and extn1 */
- driv = -1; /* ask for working drive */
- strcpy(extn3," "); /* no initial text for user-editable extensions */
- strcpy(extn4," "); /* but must fill with spaces so it will edit */
- strcpy(path,"\\"); /* original path spec just starts at root */
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- multi();
- }
-
-
- /****************************************************************/
- /* dispatches all accessory tasks */
- /****************************************************************/
- multi()
- {
- int event;
-
- do { /* big loop processes events until window close message */
-
- event = evnt_multi(MU_MESAG | MU_BUTTON | MU_KEYBD,
- 1,1,butdown,
- 0,0,0,0,0,
- 0,0,0,0,0,
- msgbuff,0,0,&mx,&my,&ret,&ret,&keycode,&ret);
-
- wind_update(TRUE);
- wind_get(wi_handle,WF_TOP,&top_window,&ret,&ret,&ret); /* added */
-
- if (event & MU_MESAG)
- switch (msgbuff[0]) {
-
- case WM_REDRAW:
- do_redraw(msgbuff[4],msgbuff[5],msgbuff[6],msgbuff[7]);
- break;
-
- case WM_NEWTOP:
- case WM_TOPPED:
- wind_set(wi_handle,WF_TOP,0,0,0,0);
- break;
-
- case WM_SIZED:
- case WM_MOVED:
- if(msgbuff[6]<MIN_WIDTH)msgbuff[6]=MIN_WIDTH;
- if(msgbuff[7]<MIN_HEIGHT)msgbuff[7]=MIN_HEIGHT;
- wind_set(wi_handle,WF_CURRXYWH,msgbuff[4],msgbuff[5],msgbuff[6],msgbuff[7]);
- wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
- break;
-
- case WM_FULLED:
- if(fulled){
- wind_calc(WC_WORK,WI_KIND,xold,yold,wold,hold,
- &xwork,&ywork,&wwork,&hwork);
- wind_set(wi_handle,WF_CURRXYWH,xold,yold,wold,hold);}
- else{
- wind_calc(WC_BORDER,WI_KIND,xwork,ywork,wwork,hwork,
- &xold,&yold,&wold,&hold);
- wind_calc(WC_WORK,WI_KIND,xdesk,ydesk,wdesk,hdesk,
- &xwork,&ywork,&wwork,&hwork);
- wind_set(wi_handle,WF_CURRXYWH,xdesk,ydesk,wdesk,hdesk);
- }
- fulled ^= TRUE;
- break;
-
- } /* switch (msgbuff[0]) */
-
- if ((event & MU_BUTTON)&&(wi_handle == top_window))
- if(butdown) butdown = FALSE;
- else butdown = TRUE;
-
- /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- * Note we call fsel from this event. It is important to note
- * that all five extension text strings must be 3 full characters,
- * even if those characters are spaces...
- * It is also important that the 'driv' and 'sextn' are pointers,
- * not actual integers!
- * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
- if(event & MU_KEYBD){
- stat = fsel("Select a file to try it out...",
- path,&driv,&sextn,"PRG","T??","* ",extn3,extn4,fullname);
- set_clip(xwork,ywork,wwork,hwork); /* clip full work area */
- write_info(); /* to ensure that full window is rewritten */
- }
-
- wind_update(FALSE);
-
- } while(!((event & MU_MESAG) && (msgbuff[0] == WM_CLOSED)));
- /* end of big loop processing events until WM_CLOSED message */
-
- wind_close(wi_handle);
- graf_shrinkbox(xwork+wwork/2,ywork+hwork/2,gl_wbox,gl_hbox,xwork,ywork,wwork,hwork);
- wind_delete(wi_handle);
- v_clsvwk(handle);
- appl_exit();
-
- }
-
- /****************************************************************/
- /* fill window with info from called function */
- /* This part just displays for the user what fsel() returned. */
- /****************************************************************/
- write_info()
- {
- int temp[4],vpos;
- char string[80],drivc,stats[6];
- vsf_interior(handle,2); /* fill style solid */
- vsf_style(handle,8); /* sort of the same, only more */
- vsf_color(handle,WHITE); /* fill with white when filling */
- temp[0]=xwork;
- temp[1]=ywork;
- temp[2]=xwork+wwork-1;
- temp[3]=ywork+hwork-1;
- v_bar(handle,temp); /* blank the interior */
-
- vpos = ywork + 1* gl_hchar; /* vertical position inside window */
- sprintf(string,"Sextn: %2x",sextn);
- v_gtext(handle,xwork,vpos,string);
-
- switch (driv) {
- case 0: drivc = 'A'; break;
- case 1: drivc = 'B'; break;
- case 2: drivc = 'C'; break;
- case 3: drivc = 'D'; break;
- case 4: drivc = 'E'; break;
- case 5: drivc = 'F'; break;
- default:drivc = '?';
- };
- vpos += gl_hchar; /* move down a line */
- sprintf(string,"Drive: %2d (%c)",driv,drivc);
- v_gtext(handle,xwork,vpos,string);
-
- vpos += gl_hchar;
- sprintf(string,"extn3: %-4s",extn3);
- v_gtext(handle,xwork,vpos,string);
-
- vpos += gl_hchar;
- sprintf(string,"extn4: %-4s",extn4);
- v_gtext(handle,xwork,vpos,string);
-
- vpos += gl_hchar;
- sprintf(string,"path: %-16s",path);
- v_gtext(handle,xwork,vpos,string);
-
- vpos += gl_hchar;
- sprintf(string,"file: %-24s",fullname);
- v_gtext(handle,xwork,vpos,string);
-
- switch (stat) {
- case (0): strcpy(stats,"CANC"); break;
- case (1): strcpy(stats,"OK"); break;
- case (2): strcpy(stats,"ERROR");break;
- default : strcpy(stats,"?????");
- };
- vpos += gl_hchar;
- sprintf(string,"stat: %2d (%-5s)",stat,stats);
- v_gtext(handle,xwork,vpos,string);
-
- vpos += gl_hchar;
- /* vst_color(handle,RED); */
- v_gtext(handle,xwork,vpos,"Strike any key to select file");
-
- vpos += gl_hchar;
- v_gtext(handle,xwork,vpos,"(or CLOSE this window to quit)");
- /* vst_color(handle,BLACK); */
- }
-